package designPatterns.P11_代理模式_Proxy.P03_cglib_runoob;

import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.NoOp;

public class P02 {
    public static void main(String[] args) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(TargetObject.class);
        TargetMethodCallbackFilter filter = new TargetMethodCallbackFilter();
        Callback noopCb = NoOp.INSTANCE;
        TargetInterceptor interceptor = new TargetInterceptor();
        TargetResultFixed result = new TargetResultFixed();
        Callback[] cbs = {interceptor, noopCb, result};
        enhancer.setCallbacks(cbs);
        enhancer.setCallbackFilter(filter);
        TargetObject to = (TargetObject) enhancer.create();
        System.out.println(to);
        System.out.println(to.method1("adaf"));
        System.out.println(to.method2(100));
        System.out.println(to.method3(100));
        System.out.println(to.method3(200));
    }
}
